package com.rk.study01;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

// KEYIN,VALUEIN map阶段输出的key, value
// KEYOUT,VALUEOU 期望输出的格式
public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
    int sum;
    IntWritable v = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        // 1.累加求和
        sum = 0;

        for(IntWritable value : values){
            sum += value.get();
        }

        // 2.输出
        v.set(sum);
        context.write(key, v);
    }
}
